﻿#pragma once

#include <functional>
#include "vector3.h"
#include "polygon_fill_algo.h"

template<typename T>
class TemplateAlgo
{
public:
    TemplateAlgo()
    {
        impl_.Remove(0);
    }
    T impl_;
};

class RangeFill
{
public:
    RangeFill() = delete;
    RangeFill(int32_t A, float a)
    {
        data_.Init(A, a);
        fill_impl_ = new PolygonFillSweepLineImpl();
        query_impl_ = new PolygonQuerySegmentImpl();
    }
    ~RangeFill()
    {
        delete fill_impl_;
        delete query_impl_;
    }
    RangeFill(const RangeFill &other) = delete;
    RangeFill operator = (const RangeFill &other) = delete;
public:
    using Point = Vector3;
    using Polygon = std::vector<Point>;
public:
    bool Query(const Point &point, Point &empty_point) const
    {
        return query_impl_ ? query_impl_->Query(data_, point, empty_point) : false;
    }
    /// 多边形填充
    inline bool Fill(const Polygon &polygon)
    {
        return fill_impl_ ? fill_impl_->Fill(polygon, data_) : false;
    }
    /// 圆填充
    inline bool Fill(const Point &center, float r1, float r2)
    {
        return fill_impl_ ? fill_impl_->Fill(center, r1, r2, data_) : false;
    }
    inline bool Remove(int32_t key)
    {
        return data_.Remove(key);
    }

private:
    FieldData data_;

    PolygonFillImpl* fill_impl_;  ///< 填充算法实现
    PolygonQueryImpl* query_impl_;  ///< 查询算法实现

    // using GetFillImplFunc = std::function<bool()>;
    // std::array<GetFillImplFunc, 2> fill_factory_;
};
